#include"httplib.h"
#include<iostream>
void Hello(const httplib::Request &req,httplib::Response &rsp)   
{
     rsp.set_content("Hello world!","text/plain");   //服务端做出响应->给浏览器，只显示正文
     rsp.status=200;
    
}

void Number(const httplib::Request &req,httplib::Response &rsp)
{
  auto num=req.matches[1];                     // <-   //客户端提供的参数/number/456
  rsp.set_content(num,"text/plain");            //服务端做出响应->给浏览器，只显示正文 ,类型文本
  rsp.status=200;
}

void Multipart(const httplib::Request& req,httplib::Response &rsp)//用于上传
{
auto ret=req.has_file("file");
if(ret==false)
{std::cout<<"not file updoad\n";
rsp.status=400;
return ;}
const auto& file=req.get_file_value("file");
rsp.body.clear();
rsp.body=file.filename;
rsp.body+="\n";
rsp.set_header("Content-Type","text/plain");
rsp.status=200;
return ;

}

int main()
{
httplib::Server server; //实例化以Server类的对象用于搭建服务器


server.Get("/hi",Hello);//注册一个针对/hi的Get请求的处理函数映射关系   //客户端发送请求/hi 执行函数Hello             (Get方法)
server.Get(R"(/numbers/(\d+))",Number);                             //客户端发送请求/numbers/数字    执行函数Number (Get方法)
server.Post("/muitipart",Multipart);                                 //客户端发送请求/muitipart      执行函数Multipart (Post) 
server.listen("0.0.0.0",8080);                                       //服务端监听相当于链接
return 0;
}